<template>
	<view class="center">
		<view v-if="isad =='0分'">
			<view class="flex cv mb20" v-if="type==1">
				<ads :SwiperImglist="data.c_ad" @flags="flags" :heightsum="height"></ads>
			</view>
			<!-- #ifdef MP || H5 -->
			<view class="flex cv mb20" v-if="data.task_wx_status_j!=0">

				<view v-if="data.wx_ad_banner" class="adContainer">
					<ad :unit-id="data.wx_ad_banner" ad-intervals="30"></ad>
				</view>
				<view v-else class="adContainer">

					<ad-custom :unit-id="data.wx_ad_ys_qj" ad-intervals="30"></ad-custom>
				</view>
			</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="flex cv mb20" v-if="type==2">

			<ad :adpid="data.app_ad_banner" @load="adLoad" @close="adClose" @error="adError"></ad>
				
			</view>
			<!-- #endif -->
		</view>
	</view>
</template>
<script>
	import ads from '@/components/ads/ads.vue'
	import time from '@/util/getdateTime.js';
	export default {
		components: {
			ads
		},
		name: "gr-ad",
		props: {
			flag: {
				type: String,
				default: "novel"
			},
			data: {
				type: Object,
				default () {
					return {};
				}
			},
			height: Number,
			showCategory: Boolean,
			type: {
				type: [Number, String],
				default: 0
			},
			width: {
				type: [String, Number],
				default: "160rpx"
			}
		},
		data() {
			return {
				config: {},
				tt: 0,
				isad: '0分',
			}
		},
		methods: {
			update_ad() {

				this.config = uni.getStorageSync('config');
				this.tt = uni.getStorageSync('config_time');
				this.isad = time.getInervalHour(time.dtime(), this.tt)

			},
			onadload(e) {
				console.log('广告数据加载成功');
			},
			onadclose(e) {
				console.log("onadclose", e);
			},
			onaderror(e) {
				// 广告加载失败
				console.log("onaderror: ", e.detail);
			},
			adLoad(e) {
				console.log("adLoad", e);
			},
			adError(e) {
				console.log("adError", e);
			},
			adClose(e) {
				console.log("adClose", e);
			},
			flags(e) {
				console.log('e', e)
				this.config = uni.getStorageSync('config');
				this.tt = parseInt(uni.getStorageSync('config_ad_time'));
				if (e.ad_type == 1) {
					if (this.config.task_status == 1 && this.config.task_d_status == 1) {
						//let st = this.tt ? time.timej(this.config.task_d_m, this.tt) : time.timej(this.config.task_d_m, 0)
						uni.setStorageSync('config_ad_time', this.tt ? (this.tt + parseInt(this.config.task_d_m)) : this
							.config.task_d_m);
					}
					plus.runtime.openURL(e.ad_url);
				} else {


				}
			}
		}
	}
</script>
<style>
	.mb20 {
		margin: 0 auto;
	}

	.center {
		text-align: center;
	}

	.adContainer {
		width: 100%;
	}
</style>
